import smtplib
from email.mime.text import MIMEText
from email.header import Header


def send_mail(content):
    host = 'smtp.163.com'  # SMTP提供商服务器地址
    passwd = 'DHTFVDINMMGUCDMP'  # 授权码
    sender = 'inpermanent@163.com'  # 发送者邮箱地址
    receiver = '1053507438@qq.com'  # 接收者邮箱地址
    title = 'Today\'s IP'  # 邮件标题内容
    msg = MIMEText(content, 'plain', 'utf-8')  # 实例化 MIME 内容对象
    msg['Subject'] = Header(title, 'utf-8')  # 用 Header 对象来格式化内容
    msg['From'] = Header(sender, 'utf-8')
    msg['To'] = Header(receiver, 'utf-8')
    try:
        email = smtplib.SMTP()  # 实例化 SMTP 对象
        email.connect(host=host)  # 连接 SMTP 服务器
        email.login(sender, passwd)  # 登录
        email.sendmail(sender, receiver, msg.as_string())  # 发送邮件，内容以字符串形式
        email.quit()  # 退出
        print('Success')
    except Exception as error:
        print('error:', error)
